package com.leen.admin.controller;


import com.leen.admin.dto.DictDetailDTO;
import com.leen.admin.entity.DictDetail;
import com.leen.admin.repository.DictdetailRepository;
import com.leen.admin.service.DictdetailService;
import com.leen.admin.vo.DictDetailVO;
import com.leen.common.vo.ResponseVO;
import com.leen.common.vo.ResultEnum;
import com.leen.common.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "数据字典api")
@RequestMapping(value = "/admin")
public class DictdetailController {
    @Autowired
    private DictdetailService dictdetailService;
//
//    @Autowired
//    private DictdetailRepository dictdetailRepository;

    @ApiOperation(value = "数据查询")
    @GetMapping(value = "/dictdetail/data")
    public ResultVO<ResponseVO>search( DictDetailDTO dictDetailDTO){
        return ResultVO.success(this.dictdetailService.search(dictDetailDTO));
    }
    @ApiOperation(value = "新增数据")
    @PostMapping(value = "/dictdetail/add")
    public ResultVO<String>add(@RequestBody DictDetail dictDetail){
        DictDetail save=this.dictdetailService.save(dictDetail);
        return save!=null?ResultVO.success(ResultEnum.DB_SUCCESS):ResultVO.failed(ResultEnum.DB_FAILED);
    }

    @ApiOperation(value = "修改数据")
    @PostMapping(value = "/dictdetail/update")
    public ResultVO<String>update(@RequestBody DictDetail dictDetail){
        DictDetail update=this.dictdetailService.save(dictDetail);
        return update!=null?ResultVO.success(ResultEnum.DB_SUCCESS):ResultVO.failed(ResultEnum.DB_FAILED);
    }

    @ApiOperation(value = "分页查询")
    @GetMapping(value = "/dictdetail/searchPage")
    public ResultVO<String> searchPage(DictDetailDTO dictDetailDTO){
        ResponseVO search=this.dictdetailService.search(dictDetailDTO);
        return ResultVO.success(search);
    }

    @ApiOperation(value = "根据dictId查询值")
    @GetMapping(value = "/dictdetail/{dictId}")
    public ResultVO findByDictId(@PathVariable(value = "dictId") Long dictId){
        List<DictDetailVO> detailList = this.dictdetailService.findByDictId(dictId);

        return  detailList==null? ResultVO.failed(ResultEnum.PARAMS_FAILED):  ResultVO.success( detailList);
    }




}
